import { uniStorage } from '@/utils/storage'

export const userStore = defineStore('userInfo', {
    state: (): AnyObject => ({
        token: '',
        userInfo: {},
        rightList: [],
    }),
    actions: {
        logout() {
            this.token = ''
            this.userInfo = {}
            this.rightList = []
        },
        setToken(token: string) {
            this.token = `Bearer ${token}`
        },
        setUserInfo(userInfo: AnyObject) {
            this.userInfo = userInfo
        },
        setRight(rightList: string[]) {
            this.rightList = rightList
        },
    },
    // 持久化插件
    persist: {
        enabled: true,
        strategies: [
            {
                key: 'userInfo',
                storage: uniStorage,
            },
        ],
    },
})
